﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:h="clr-namespace:Halfwit"
                    xmlns:v="clr-namespace:Halfwit.ViewModels"
                    xmlns:tw="clr-namespace:TweetSharp.Twitter.Model;assembly=TweetSharp.Twitter.ClientProfile"
                    >

    <!-- 
    These templates are used to display ViewModel-specific UI above the row
    of toolbar buttons on the TweetsView page.
    -->
    
    <DataTemplate DataType="{x:Type v:HomeViewModel}">
    </DataTemplate>

    <DataTemplate DataType="{x:Type v:MentionsViewModel}">
    </DataTemplate>

    <DataTemplate DataType="{x:Type v:MessagesViewModel}">
    </DataTemplate>

    <DataTemplate DataType="{x:Type v:UserViewModel}">
        <StackPanel Margin="2,4">
            <StackPanel.Resources>
                <Style x:Key="CollapsedIfEmpty" TargetType="TextBlock">
                    <Setter Property="Visibility" Value="Visible"/>
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding Text,RelativeSource={RelativeSource Self}}" Value="">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </StackPanel.Resources>
                
            <DockPanel>
                <Button 
                    x:Name="submit" 
                    DockPanel.Dock="Right" 
                    IsDefault="True" 
                    Command="{Binding Search}" 
                    ToolTip="Perform Search" 
                    VerticalAlignment="Center"
                    Style="{StaticResource FlatButtonStyle}"
                    >
                    <Image Source="/Images/go.png" Height="16" Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" />
                </Button>
                <Label Padding="0" Target="{Binding ElementName=searchText}" Content="_Name:" VerticalAlignment="Center" />
                <TextBox x:Name="searchText" h:UsernameLookup.Trigger="StartOfText"  Margin="4,0,2,0" Text="{Binding Text,UpdateSourceTrigger=PropertyChanged}" />
            </DockPanel>

            <DockPanel>
                <DockPanel.Resources>
                    <Style TargetType="Button" BasedOn="{StaticResource FlatButtonStyle}" />

                    <Style TargetType="Image">
                        <Setter Property="Width" Value="16" />
                        <Setter Property="Height" Value="16" />
                        <Setter Property="RenderOptions.BitmapScalingMode" Value="NearestNeighbor" />
                    </Style>
                </DockPanel.Resources>

                <Button DockPanel.Dock="Right" 
                        Margin="0,2"
                        Style="{StaticResource FlatButtonStyle}" 
                        Command="{Binding DirectMessage}"
                        CommandParameter="{Binding User}" 
                        ToolTip="{Binding User,Converter={StaticResource MessageText}}"
                        >
                    <Image Source="/Images/messages.png" />
                </Button>
                <Button DockPanel.Dock="Right" 
                        Margin="0,2"
                        Style="{StaticResource FlatButtonStyle}" 
                        Command="{Binding Follow}"
                        CommandParameter="{Binding User}" 
                        ToolTip="{Binding User,Converter={StaticResource FollowText}}"
                        >
                    <Image Source="/Images/user.png" />
                </Button>
                <TextBlock Margin="2" 
                           Style="{StaticResource CollapsedIfEmpty}" 
                           FontWeight="Bold" 
                           Text="{Binding User.Name}"
                           VerticalAlignment="Bottom"
                           />
            </DockPanel>
            
            <TextBlock Margin="2" Style="{StaticResource CollapsedIfEmpty}" Text="{Binding User.Location}" />
            <TextBlock Margin="2" Style="{StaticResource CollapsedIfEmpty}" Text="{Binding User.Description}" TextWrapping="Wrap" />
            <TextBlock Margin="2">
                <TextBlock.Style>
                    <Style TargetType="TextBlock">
                        <Setter Property="Visibility" Value="Visible" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding User.Url}" Value="{x:Null}">
                                <Setter Property="Visibility" Value="Collapsed" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
                <Hyperlink Command="{Binding NavigateToUrl}" CommandParameter="{Binding User.Url}"><TextBlock Text="{Binding User.Url}" /></Hyperlink>
            </TextBlock>
        </StackPanel>
    </DataTemplate>

    <DataTemplate DataType="{x:Type v:SearchViewModel}">
        <DockPanel Margin="2,4">
            <Button 
                DockPanel.Dock="Right" 
                Command="{Binding SaveSearch}" 
                ToolTip="Save this search"  
                VerticalAlignment="Center"
                Style="{StaticResource FlatButtonStyle}"
                >
                <Image Source="/Images/save.png" Height="16" Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" />
            </Button>
            <Button 
                x:Name="submit" 
                DockPanel.Dock="Right" 
                IsDefault="True" 
                Command="{Binding Search}" 
                ToolTip="Perform Search"  
                VerticalAlignment="Center"
                Style="{StaticResource FlatButtonStyle}"
                >
                <Image Source="/Images/go.png" Height="16" Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" />
            </Button>
            <Label Padding="0" Target="{Binding ElementName=searchText}" Content="_Find:" VerticalAlignment="Center" />

            <ComboBox x:Name="searchText" 
                      Margin="4,0,2,0" 
                      DisplayMemberPath="Query"
                      IsEditable="True"
                      Text="{Binding Text,UpdateSourceTrigger=PropertyChanged}"
                      HorizontalContentAlignment="Stretch"
                      ItemsSource="{Binding SavedSearches}">
                <ComboBox.ItemTemplate>
                    <DataTemplate DataType="{x:Type tw:TwitterSavedSearch}">
                        <DockPanel>
                            <Button 
                                DockPanel.Dock="Right" 
                                Style="{StaticResource FlatButtonStyle}"
                                Command="{Binding DataContext.DeleteSavedSearch,RelativeSource={RelativeSource FindAncestor,AncestorType=ComboBox}}" 
                                CommandParameter="{Binding}"
                                ToolTip="Delete this saved search"  
                                VerticalAlignment="Center"
                                Margin="2,2,0,2"
                                Width="28"
                                >
                                <Image Source="/Images/delete.png" Height="16" Width="16" RenderOptions.BitmapScalingMode="NearestNeighbor" />
                            </Button>
                            <TextBlock Text="{Binding Query}" />
                        </DockPanel>
                    </DataTemplate>
                </ComboBox.ItemTemplate>
                
            </ComboBox>
        </DockPanel>
    </DataTemplate>
</ResourceDictionary>